<template>
  <div class="dashboard-container">
    <component :is="currentRole" />
	 
	 <el-dialog title="首次登录设置密码" :visible.sync="dialogFormVisible" class="form">
	   <el-form :model="form" :rules="rules" autocomplete="on" label-width="100px" ref="form">
	     <el-form-item label="输入密码:" prop="originPassward" required>
	       <el-input v-model="form.originPassward" autocomplete="off" type="passward" show-password></el-input>
	     </el-form-item>
	     <el-form-item label="确认密码："  prop="surePassward" required>
	       <el-input v-model="form.surePassward" autocomplete="off" type="passward" show-password></el-input>
	     </el-form-item>
	   </el-form>
	   <div slot="footer" class="dialog-footer">
	     <el-button @click="dialogFormVisible = false">取 消</el-button>
	     <el-button type="primary" @click="onSubmitPwd">确 定</el-button>
	   </div>
	 </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import adminDashboard from './admin'
import editorDashboard from './editor'

export default {
  name: 'Dashboard',
  components: { adminDashboard, editorDashboard },
  data() {
	const validateOriginPassward = (rule, value, callback) => {
	  	if (value.length < 1) {
	  		callback(new Error('密码不能为空！'))
	  	} else {
	  		callback()
	  	}
	}
	const validateSurePassward = (rule, value, callback) => {
	  	if (value.length < 1) {
	  		callback(new Error('请再次确认密码！'))
	  	} else {
	  		callback()
	  	}
	}
   return {
      currentRole: 'adminDashboard',
		isInnerAdmin: true,//是否是内部管理员
		dialogFormVisible: false,
		form:{
			originPassward:'',
			surePassward:''
		},
		rules: {
			originPassward: [{ required: true, trigger: 'blur', validator: validateOriginPassward }],
			surePassward: [{ required: true, trigger: 'blur', validator: validateSurePassward }]
		},
    }
  },
  computed: {
    ...mapGetters([
      'roles',
		'userinfo'
    ])
  },
  created() {
    if (!this.roles.includes('admin')) {
      this.currentRole = 'editorDashboard'
    }
  },
  methods:{
	  // 提交信息
	  onSubmitPwd(){
		  this.dialogFormVisible = false;
		  this.$message({
				type: 'success',
				message: '密码设置成功！'
		  });
	  }
  }
}
</script>
<style lang="scss" scoped="scoped">
	.form{
		width:66%;
		margin:0 auto;
	}
</style>
